/*
 * Copyright (c) 2002 Boris Pruessmann and others. All rights reserved. This
 * program and the accompanying materials are made available under the terms of
 * the Common Public License v0.5 which accompanies this distribution, and is
 * available at http://www.eclipse.org/legal/cpl-v05.html
 * 
 * Contributors: Boris Pruessmann - Initial implementation.
 */
package net.sourceforge.perforce.ui.action;

import net.sourceforge.perforce.core.resources.RemoteFile;
import net.sourceforge.perforce.ui.internal.Policy;
import net.sourceforge.perforce.ui.views.HistoryView;

import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.operation.IRunnableWithProgress;

import java.lang.reflect.InvocationTargetException;

/**
 * ObjectContribution for net.sourceforge.perforce.core.resources.RemoteFile
 * 
 * @version $Revision: 488 $
 * @author <a href="mailto:bpruessmann@users.sourceforge.net">Boris
 *         Pruessmann</a>
 */
public class ShowHistoryAction extends PerforceAction {
  //----------------------------------------------------------------------------
  // -- Public Methods

  @Override
  public void run(IAction action) {
    run(new IRunnableWithProgress() {
      @SuppressWarnings("unused")
      // InvocationTargetException, InterruptedException
      public void run(IProgressMonitor monitor) throws InvocationTargetException,
          InterruptedException {
        RemoteFile[] files = getSelectedRemoteFiles();
        Policy.assertTrue(files.length == 1);

        HistoryView view = HistoryView.openInActivePerspective();
        if (view != null) {
          view.showHistory(files[0]);
        }
      }
    }, PROGRESS_BUSYCURSOR);
  }

  // ---------------------------------------------------------------------------
  // Protected Methods

  @Override
  protected boolean isEnabled() {
    RemoteFile[] resources = getSelectedRemoteFiles();
    return resources.length == 1;
  }
}
